﻿using Aribaccio;
using Aribaccio.Core;
using Aribaccio.Device;
using BDPAutodetect.Device;
using BDPAutodetect.Models;
using BDPAutodetect.Simcore;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BDPAutodetect.Simulator
{
    public partial class SimulatorSensorViewModel : SimulatorViewModel
    {
        /// <summary>
        /// 设备仿真实例
        /// </summary>
        protected DeviceSimulatorSensorSign? DeviceSimulatorSensor { get; set; }
        /// <summary>
        /// 模块1是否启动
        /// </summary>
        [ObservableProperty]
        protected bool isStartupModule1 = false;
        /// <summary>
        /// 模块2是否启动
        /// </summary>
        [ObservableProperty]
        protected bool isStartupModule2 = false;
        /// <summary>
        /// 模块3是否启动
        /// </summary>
        [ObservableProperty]
        protected bool isStartupModule3 = false;

        /// <summary>
        /// 构造函数
        /// </summary>
        public SimulatorSensorViewModel(DeviceType argDeviceType, DeviceModule argDeviceModule)
            : base(argDeviceType, argDeviceModule)
        {
            this.DeviceSimulatorSensor = (DeviceSimulatorSensorSign?)DeviceSimulator;
        }

        /// <summary>
        /// 启动开关
        /// </summary>
        [RelayCommand]
        public void ExecuteStartupModule(DeviceModule argModule)
        {
            if (this.DeviceSimulatorSensor == null) return;
            SwitchType switchType = SwitchType.Off;
            switch (argModule)
            {
                case DeviceModule.One:
                    switchType = this.IsStartupModule1 ? SwitchType.On : SwitchType.Off;
                    break;
                case DeviceModule.Two:
                    switchType = this.IsStartupModule2 ? SwitchType.On : SwitchType.Off;
                    break;
                case DeviceModule.Three:
                    switchType = this.IsStartupModule3 ? SwitchType.On : SwitchType.Off;
                    break;
            }
            this.DeviceSimulatorSensor.StartupSwitch(argModule, switchType);
        }
    }
}
